#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<assert.h>
using namespace std;

#include <stdlib.h>  // for malloc

typedef char BTDataType;

typedef struct BinaryTreeNode
{
    BTDataType _data;
    struct BinaryTreeNode* _left;
    struct BinaryTreeNode* _right;
}BTNode;

// Helper function to create a binary tree node
BTNode* CreateNode(BTDataType data) {
    BTNode* newNode = (BTNode*)malloc(sizeof(BTNode));
    if (newNode != NULL) {
        newNode->_data = data;
        newNode->_left = NULL;
        newNode->_right = NULL;
    }
    return newNode;
}

// Helper function to recursively create a binary tree from an array
BTNode* BinaryTreeCreateHelper(BTDataType* a, int n, int* pi) {
    if (*pi >= n || a[*pi] == '#') {
        (*pi)++;
        return NULL;
    }
    cout << a[n];
    BTNode* root = CreateNode(a[(*pi)++]);
    root->_left = BinaryTreeCreateHelper(a, n, pi);
    root->_right = BinaryTreeCreateHelper(a, n, pi);

    return root;
}

BTNode* BinaryTreeCreate(BTDataType* a, int n, int* pi) {
    if (a == NULL || n <= 0 || pi == NULL) {
        return NULL;
    }

    return BinaryTreeCreateHelper(a, n, pi);
}

int main() {
    BTDataType arr[] = { 'A', 'B', 'D', '#', '#', 'E', '#', 'H', '#', '#', 'C', 'F', '#', '#', 'G', '#', '#' };
    int size = sizeof(arr) / sizeof(arr[0]);
    int index = 0;

    BTNode* root = BinaryTreeCreate(arr, size, &index);

}
